import { getJSON } from '@quickearth/core'
import dayjs from 'dayjs'
import apiList from '../api/api'
import { ElMessage } from 'element-plus'

const defaultData = () => ({
  componentsVisible: {
    // 国家站
    gjz: false,
    // 区域站
    qyz: false,
    // 站点名称
    zdmc: false,
    // 站号
    zh: false,
    // 县名
    xm: false,
    labels: '全部',
    // 观测值
    gcz: false,
    cityCode: '140100',
    countryCode: '140106',
    pos: {
      lat: '37.815',
      lng: '112.5878'
    }
  },
  NavActive: '11D02',
  mappointData: [],
  // 地图加载
  mapLoading: false
})

export const usedisasterStore = defineStore({
  id: 'disaster',
  state: () => {
    return defaultData()
  },
  getters: {},
  actions: {
    mappointdisasterData() {
      apiList
        .disasterPointList({
          countyCode: this.componentsVisible.countryCode
            ? this.componentsVisible.countryCode
            : '140106',
          cityCode: this.componentsVisible.cityCode
            ? this.componentsVisible.cityCode
            : '140100',
          disasterType: this.NavActive
        })
        .then(res => {
          if (res.code == 200) {
            this.mappointData = res.data
          } else {
            ElMessage({
              showClose: true,
              message: res.msg,
              type: 'error'
            })
          }
        })
    },
    // 销毁 并初始化数据
    handleUnmountedInitData() {
      const defaultDataObj = defaultData()
      Object.keys(defaultDataObj).forEach(item => {
        this[item] = defaultDataObj[item]
      })
    }
  }
})
